package org.ade.monak.anak.service.gate.monak;

import org.ade.monak.anak.boundary.PendaftaranAnak;
import org.ade.monak.anak.entity.Ortu;
import org.ade.monak.anak.service.DatabaseThreadService;
import org.ade.monak.anak.service.storage.DatabaseManagerAnak;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

public class ReceiverPendaftaranAnak {

	public ReceiverPendaftaranAnak
		(Context context, DatabaseThreadService databaseThread, String idOrtu){
		databaseManager = new DatabaseManagerAnak(context);
		this.databaseThread	= databaseThread;
		this.context = context;
		this.idOrtu = idOrtu;
	}
	
	public void receivePendaftaranAnak(String noHp, String idAnak){
		Intent intent = new Intent(context,PendaftaranAnak.class);
		
		Bundle bundle = new Bundle();
		
		bundle.putString("noHp", noHp);
		bundle.putString("idAnak", idAnak);
		bundle.putString("idOrtu", idOrtu);
		intent.putExtras(bundle);
		intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		context.startActivity(intent);
		
	}
	
	public void receiveUpdateAnak( String noHp, String idAnak){		
		
		Intent intent = new Intent(context,PendaftaranAnak.class);
		
		Bundle bundle = new Bundle();
		
		bundle.putString("noHp", noHp);
		bundle.putString("idAnak", idAnak);
		bundle.putString("idOrtu", idOrtu);
		intent.putExtras(bundle);

		intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		
		context.startActivity(intent);
		
	}
	
	public void receiveHapusAnak(final String noHp,final String idAnak){
		
		databaseThread.addDatabaseThread(new Runnable(){

			public void run() {
				Ortu ortu = new Ortu();
				ortu.setIdOrtu(idOrtu);
				ortu.setIdAnak(idAnak);
				ortu.setNoHp(noHp);
				databaseManager.deleteOrtu(ortu);
				SenderKonfirmasi senderKonfirmasi	= new SenderKonfirmasi(context, ortu);
				senderKonfirmasi.sendKonfirmasiHapusAnak();
			}
			
		});
		
	
	}
	
	private final DatabaseManagerAnak databaseManager;
	private final DatabaseThreadService databaseThread;
	private final String idOrtu;
	private final Context context;
}
